import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";

const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    name: "Home",
    component: () => import(/* webpackChunkName: "Home" */ "../views/Home.vue"),
  },
  {
    path: "/todolist",
    name: "todolist",
    component: () => import("../views/todolist/index.vue"),
  },
  {
    path: "/transition",
    name: "transition",
    component: () => import("../views/transition/index.vue"),
  },
  {
    path: "/schema",
    name: "schema",
    component: () => import("../views/schema.vue"),
  },
  {
    path: "/layout",
    name: "layout",
    component: () => import("../views/layout/index.vue")
  },
  {
    path: "/drag",
    name: "drag",
    component: () => import("../views/drag/index.vue")
  },
  {
    path: "/echart",
    name: "echart",
    component: () => import("../views/echhart/index.vue")
  },
  // 富文本
  {
    path: "/edit",
    name: "edit",
    component: () => import("../views/edit/index.vue")
  },
  // 时间
  {
    path: '/time',
    name: 'time',
    component: () => import("../views/time/index.vue")
  },
  {
    path: '/canvas',
    name: 'canvas',
    component: () => import("../views/canvas/index.vue")
  },
  // threeJS
  {
    path: '/three',
    name: 'three',
    component: () => import("../views/three/index.vue")
  },
  // VR看房house
  {
    path: '/vrhouse',
    name: 'vrhouse',
    component: () => import("../views/three/vrhouse.vue")
  },
  // 虚拟列表
  {
    path: '/virtualList',
    name: 'virtualList',
    component: () => import('../views/virtualList/index.vue')
  },
  // 在线代码编辑器
  {
    path: '/monaco',
    name: 'monaco',
    component: () => import('../views/monaco/index.vue')
  },
  // 识别图片提取文字
  {
    path: '/drawpic',
    name: 'drawpic',
    component: () => import('../views/drawpic/index.vue')
  },
  // 流程
  {
    path: '/jsplumn',
    name: 'jsplumn',
    component: () => import('../views/jsplumn/index.vue')
  }
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

// console.log(router.addRoute)
let hasRoles = true
router.beforeEach((to, from, next) => {
  if (hasRoles) {
    router.options.routes.forEach(item => router.addRoute(item))
    hasRoles = false
    next({...to, replace: true})
  } else {
    next()
  }
})

router.afterEach(() => {
  // console.log("hello")
})

export default router;
